home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / examples / xsum.a < prev    next >
Text File  |  1998-08-27  |  5KB  |  229 lines

  1. ;    OPT    l-    ; Make executable code (DevPac etc.)
  2.     EXEOBJ        ; Make executable code (Macro68 etc.)
  3.  
  4. ; Note:    Comment EXEOBJ out and remove semi-colon from first line
  5. ;    if you are using DevPac or some compatible assembler
  6.  
  7. *****************************************************************
  8. *            xSum.asm V1.0                *
  9. *    simple example for XPK interface by Ch.Schneider    *
  10. *****************************************************************
  11. *    Sums up all bytes in compressed or uncompressed file    *
  12. *    This is a typical read-and-process xpk application.    *
  13. *    Try it out... xSum a file, then compress it and xSum    *
  14. *    it again. The result should be the same.        *
  15. *    NOTE: Only start this from CLI!    No WBStartup        *
  16. *          included for simplicity! No CLI Parsing is done!    *
  17. *****************************************************************
  18.  
  19.     OUTPUT    xSum        ; Output to file "xSum" (Macro68, DevPac, etc.)
  20. ;    OBJFILE    "xSum"        ; Output to file "xSum" (Adapt etc.)
  21.  
  22.     INCLUDE    AINCLUDE:IncDirs.i
  23.     INCLUDE    xpk/xpk.i
  24.  
  25. ************* Kludge to get around include problem :-)) ********
  26. ; Note: Not everyone really needs this stuff: Macro68 provides
  27. ; the possibility to have resident & preassembled includes ;-) TINAR :-)
  28. _LVOAllocMem        EQU    -198
  29. _LVOFreeMem        EQU    -210
  30. _LVOOpenLibrary        EQU    -552
  31. _LVOCloseLibrary    EQU    -414
  32.  
  33. _LVOOpen        EQU    -30
  34. _LVOClose        EQU    -36
  35. _LVOWrite        EQU    -48
  36. _LVOOutput        EQU    -60
  37.  
  38. CALLSYS MACRO        ; call a library via A6 without having to see _LVO
  39.     JSR    _LVO\1(A6)
  40.     ENDM
  41. ********* EOK (End-Of-Kludge :-) ***********
  42.  
  43. start:
  44.     clr.b    -1(a0,d0.l)        ; Convert LF to 0
  45.     move.l    a0,filename        ; Store commandline (no parsing!)
  46.  
  47. **************** Opening libraries **************
  48.     move.l    4,a6            ; ExecBase
  49.     lea    dosname,a1
  50.     moveq    #0,d0            ; We don't care about version numbers
  51.     CALLSYS    OpenLibrary
  52.     lea    CannotOpenDosTxt,a0
  53.     move.l    d0,dosbase        ; Store DOS Library base!
  54.     beq    cleanup            ; ERROR -> Exit
  55.  
  56.     lea    xpkname,a1
  57.     moveq    #0,d0            ; We don't care about version numbers
  58.     CALLSYS    OpenLibrary
  59.     lea    CannotOpenXPKTxt,a0
  60.     move.l    d0,xpkbase        ; Store XPK Library base!
  61.     beq    cleanup            ; ERROR -> Exit
  62.  
  63. **************** Loading (and perhaps decrunching) file **************
  64.     move.l    xpkbase,a6        ; XPKBase to A6
  65.     lea    tags,a0
  66.     CALLSYS    XpkUnpack
  67.  
  68.     tst.l    d0
  69.     beq    noerrorloadingfile
  70.     
  71. **************** Error loading file **************
  72.     lea    errbuf,a0
  73.     move.l    a0,a1
  74. 1$
  75.     tst.b    (a1)+
  76.     bne    1$            ; Get terminating NULL
  77.     move.b    #10,-(a1)        ; Convert it to a LF
  78.     bra    cleanup
  79.  
  80. **************** Calculating Sum **************
  81. noerrorloadingfile:
  82.     move.l    outbuf,a0
  83.     moveq    #0,d0
  84.     move.l    outlen,d7
  85. 1$
  86.     moveq    #0,d1
  87.     move.b    (a0)+,d1
  88.     add.l    d1,d0            ; Calculate Sum...
  89.     subq.l    #1,d7
  90.     bne    1$
  91.  
  92.     bsr    printnumber        ; Simple number printing routine
  93.  
  94.     suba.l    a0,a0            ; No error msg
  95. ************ General Cleanup Routine *************
  96. cleanup:
  97.     bsr    print            ; Print error msg!
  98.  
  99.     move.l    4,a6
  100.     move.l    outbuf,d0
  101.     beq    1$
  102.     move.l    d0,a1
  103.     move.l    outbuflen,d0
  104.     CALLSYS    FreeMem            ; Free XPK output buffer
  105. 1$
  106.  
  107.     move.l    xpkbase,d0
  108.     beq    2$            ; Library not open
  109.     move.l    d0,a1
  110.     CALLSYS    CloseLibrary        ; Close XPK library
  111. 2$
  112.     move.l    dosbase,d0
  113.     beq    3$            ; Library not open
  114.     move.l    d0,a1
  115.     CALLSYS    CloseLibrary        ; Close Dos library
  116. 3$
  117.     moveq    #0,d0            ; No error code!
  118.     rts
  119.  
  120.  
  121. ********************** Support routines ********************
  122. *************** Simple Decimal Number Printing Routine *****
  123. printnumber:    ; D0 = Number
  124.     movem.l    d2-d7/a2-a6,-(a7)
  125.     lea    numberbuffer,a0
  126.  
  127.     lea    powertentable,a1
  128.     move.l    a0,a2
  129.     moveq    #'0',d2
  130. 1$
  131.     move.l    (a1)+,d1
  132.     beq    4$
  133.     cmp.l    d1,d0
  134.     blo    1$
  135. 2$
  136.     moveq    #'0'-1,d2
  137. 3$
  138.     addq.b    #1,d2
  139.     sub.l    d1,d0
  140.     bcc    3$
  141.     add.l    d1,d0
  142. 4$
  143.     move.b    d2,(a2)+
  144.     move.l    (a1)+,d1
  145.     bne    2$
  146.  
  147.     move.b    #10,(a2)+        ; Append LF!
  148.     clr.b    (a2)
  149.     bsr    print            ; Output string
  150.  
  151.     movem.l    (a7)+,d2-d7/a2-a6
  152.     rts
  153.  
  154.  
  155. *************** Print String routine *****
  156. print:    ; A0 = String
  157.     movem.l    d2-d7/a2-a6,-(a7)
  158.     move.l    a0,d2
  159.     beq    99$            ; No string!
  160.     moveq    #-1,d3
  161. 1$
  162.     addq.l    #1,d3
  163.     tst.b    (a0)+            ; Calc string length!
  164.     bne    1$
  165.  
  166.     move.l    dosbase,d0
  167.     beq    99$            ; No Doslibrary!
  168.     move.l    d0,a6
  169.     CALLSYS    Output            ; Get output filehandle
  170.     move.l    d0,d1            ; Filehandle
  171.     beq    99$            ; No Output!
  172.  
  173.     CALLSYS    Write            ; Write string!
  174. 99$
  175.     movem.l    (a7)+,d2-d7/a2-a6
  176.     rts
  177.  
  178.  
  179. ***************************************
  180. *************** DATA Part *************
  181. ***************************************
  182.     SECTION    data,data
  183. dosbase:    dc.l    1
  184. xpkbase:    dc.l    1
  185.  
  186. powertentable:
  187.     dc.l    1000000000
  188.     dc.l    100000000
  189.     dc.l    10000000
  190.     dc.l    1000000
  191.     dc.l    100000
  192.     dc.l    10000
  193.     dc.l    1000
  194.     dc.l    100
  195.     dc.l    10
  196.     dc.l    1
  197.     dc.l    0
  198.     dc.l    0
  199.  
  200. tags:
  201.         dc.l    XPK_InName
  202. filename:    dc.l    0            ; The file name to be read
  203.         dc.l    XPK_GetError,errbuf    ; A pointer to the error message buffer
  204.         dc.l    XPK_GetOutBuf
  205.         dc.l    outbuf            ; Sets a pointer to the output buffer
  206.         dc.l    XPK_GetOutLen
  207.         dc.l    outlen            ; Sets the number of bytes written
  208.         dc.l    XPK_GetOutBufLen
  209.         dc.l    outbuflen        ; Sets the length of the output buffer
  210.         dc.l    XPK_PassThru,-1        ; Will pass through uncompressed data
  211.         dc.l    TAG_DONE
  212.  
  213.  
  214. outbuf:        ds.l    1
  215. outlen:        ds.l    1
  216. outbuflen:    ds.l    1
  217.  
  218. ************** Byte size Data ***********
  219. errbuf:        ds.b    XPKERRMSGSIZE+1        ; +1 to make room for LF
  220. numberbuffer:    ds.b    12            ; Space for 10 digits + LF + 0
  221.  
  222. dosname:    dc.b    'dos.library',0
  223. xpkname:    XPKNAME
  224.  
  225. CannotOpenDosTxt:    dc.b    "Cannot open dos.library!",10,0
  226. CannotOpenXPKTxt:    dc.b    "Cannot open xpkmaster.library!",10,0
  227.  
  228.     END
  229.